<template>
  <view>
    <circleDetails ref="circleDetails" :options="page.options"></circleDetails>
  </view>
</template>

<script setup>
  import { onLoad, onShareAppMessage,onShow } from '@dcloudio/uni-app';
  import { computed, onMounted, reactive, ref } from 'vue';
  import CircleDetails from '@/pages/familyPage/components/circleDetails.vue';
  import sheep from '@/sheep';

  const page = reactive({
    options: {},
  });
  const bind_id = computed(() => sheep.$store('AI').bind_id);
  const isLogin = computed(() => sheep.$store('user').isLogin);

  onLoad((options) => {
    page.options = options;
    if (!!options.spid) {
      sheep.$store('AI').setBindId(options.spid);
    }
  });

  onShow(async () => {
    if (!!bind_id.value && !!isLogin.value) {
      const { code } = await sheep.$api.user.bindParent({ parent_id: bind_id.value });
      if (code == 1) {
        sheep.$store('AI').setBindId('');
      }
    }
  });

  const circleDetails = ref();
  onMounted(async () => {
    await circleDetails._value.getFamilyCircle();
    await circleDetails._value.getCommentList();
    await circleDetails._value.setHeightCommit();
  });

  // #ifdef MP-WEIXIN
  onShareAppMessage((res) => {
    console.log(res);
    // 家庭圈分享
    if (res.from == 'button') {
      return {
        title: res.target.dataset.info.circle.content.replace(/<[^>]*>/g, ''),
        path: res.target.dataset.path,
        imageUrl: !!res.target.dataset.info.circle.images && res.target.dataset.info.circle.images.length > 0 ? res.target.dataset.info.circle.images[0].image : `${IMG_URL.value}/index/share_background_defult.png`,
      };
    }
  });
  // #endif
</script>


<style scoped lang="scss">

</style>
